{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加轮播图</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="banner_title" lay-verify="required" placeholder="标题" class="layui-input ">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">图片：</label>
                            <input type="hidden" name="banner_img" id="lay-img" lay-verify="image">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">是否上架：</label>
                            <div class="layui-input-block">
                                <select name="banner_status" >
                                    <option value="1" selected>上架</option>
                                    <option value="2" >下架</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">排序：</label>
                            <div class="layui-input-block">
                                <input type="text" name="banner_sort" lay-verify="required" placeholder="排序" class="layui-input" oninput="value=value.replace(/[^\d]/g,'')">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group" id="banner_type">
                            <label class="layui-form-label">内链类型：</label>
                            <div class="layui-input-block">
                                <select name="banner_type" lay-filter="role1">
                                    <option value="1" selected>比赛消息</option>
                                    <option value="2" >热门老师</option>
                                    <option value="3" >精品公开课</option>
                                    <option value="4" >题库</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="match_id">
                            <label class="layui-form-label">选择比赛消息：</label>
                            <div class="layui-input-block">
                                <select name="post_id1"  xm-select="select4" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    {foreach name="res2" item="v2"}
                                    <option value="{$v2.match_id}" >{$v2.match_title}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="user_id">
                            <label class="layui-form-label">选择热门老师：</label>
                            <div class="layui-input-block">
                                <select name="post_id2"  xm-select="select5" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    {foreach name="res1" item="v1"}
                                    <option value="{$v1.user_id}" >{$v1.user_username}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="public_id">
                            <label class="layui-form-label">选择精品公开课：</label>
                            <div class="layui-input-block">
                                <select name="post_id3"  xm-select="select3" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    {foreach name="res3" item="v3"}
                                    <option value="{$v3.public_id}" >{$v3.public_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" style="display: none" id="question_id">
                            <label class="layui-form-label">选择题库：</label>
                            <div class="layui-input-block">
                                <select name="post_id4"  xm-select="select2" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    {foreach name="res4" item="v4"}
                                    <option value="{$v4.question_id}" >{$v4.question_title}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">添加
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //    var editor = wk.wang({elem:'#LAY_editor'});
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
//            data.field.lunbo_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('add')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Banner/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role1)', function(data){
            banner_type = data.value;
            if(data.value == 1){
                $("#match_id").show();
                $("#user_id").hide();
                $("#public_id").hide();
                $("#question_id").hide();
            }else if(data.value == 2){
                $("#match_id").hide();
                $("#user_id").show();
                $("#public_id").hide();
                $("#question_id").hide();
            }else if(data.value == 3){
                $("#match_id").hide();
                $("#user_id").hide();
                $("#public_id").show();
                $("#question_id").hide();
            }else if(data.value == 4){
                $("#match_id").hide();
                $("#user_id").hide();
                $("#public_id").hide();
                $("#question_id").show();
            }
        });
    });
</script>

</body>
</html>
